package controller.ranking;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import model.class1.dao.Class1Dao;
import model.member.dao.MemberDao;
import model.recipe.dao.RecipeDao;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import common.SearchDto;

public class RankingController extends MultiActionController{
	private Map<String,Object> map;
	private HttpSession session;
	private SearchDto search;
	
	private MemberDao memberDao;
	public void setMemberDao(MemberDao memberDao) {
		this.memberDao = memberDao;
	}
	private RecipeDao recipeDao;
	public void setRecipeDao(RecipeDao recipeDao) {
		this.recipeDao = recipeDao;
	}
	private Class1Dao class1Dao;
	public void setClass1Dao(Class1Dao class1Dao) {
		this.class1Dao = class1Dao;
	}
	
	///////////////////
	public ModelAndView ranking(HttpServletRequest request, HttpServletResponse response) throws Exception{
		map = new HashMap<String, Object>();
		// 한달전 날짜 구하기
		SimpleDateFormat frm= new SimpleDateFormat ("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -30);
		String aMonthAgo = frm.format(cal.getTime());
		// top 5 member
		search = new SearchDto();
		search.setKeyword("");
		search.setOffset(0);
		search.setOp_level("0");
		search.setOp_date(aMonthAgo);
		search.setOp_order("desc");
		search.setOp_rate("rate_avg");
		search.setOp_limit(5);
		map.put("memberList", memberDao.memberList(search));		
		// top 5 recipe
		map.put("recipeList",recipeDao.topRecipeList(search));
		// top 5 class
		//search.setOp_limit(3);
		//search.setOp_state("1");
		//map.put("classList",class1Dao.class1RankList(search));
		
		return new ModelAndView("/ranking/ranking.jsp","map",map);
	}
	
}
